/*
 * @Author: Superficial
 * @Date: 2021-03-04 09:29:04
 * @LastEditTime: 2021-03-04 09:41:02
 * @Description: 复制
 */
import { META } from "@/config/app.config"

export const enableCopyRight = () => {
  const copyText = () => {
    return [
      '',
      `作者：${META.author}`,
      `链接：${location.href}`,
      `来源：${META.title}`,
    ].join('\n')
  }

  const buildText = content => content + copyText()
  const buildHTML = content => content + copyText()

  document.addEventListener('copy', event => {
    if (!window.getSelection) return
    const content = window.getSelection()?.toString()
    event.clipboardData?.setData('text/plain', buildText(content))
    event.clipboardData?.setData('text/html', buildHTML(content))
    event.preventDefault()
  })
}